<?php
class Utility{
	function shorter($input, $length)
	{
		//no need to trim, already shorter than trim length
		if (strlen($input) <= $length) {
			return $input;
		}

		//find last space within length
		$last_space = strrpos(substr($input, 0, $length), ' ');
		if(!$last_space) $last_space = $length;
		$trimmed_text = substr($input, 0, $last_space);

		//add ellipses (...)
		$trimmed_text .= '...';

		return $trimmed_text;
	}
	
	private function strleft($s1, $s2) {
		return substr($s1, 0, strpos($s1, $s2));
	}

	public function selfURL() {
		$s = empty($_SERVER["HTTPS"]) ? ''
		: ($_SERVER["HTTPS"] == "on") ? "s"
		: "";
		$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
		$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
		: (":".$_SERVER["SERVER_PORT"]);
		return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
	}
	
}